//
//  ConfirmOrderProductCell.m
//  sensen_ios
//
//  Created by pro on 16/2/27.
//  Copyright © 2016年 pro. All rights reserved.
//

#import "ConfirmOrderProductCell.h"

#define cell_width self.contentView.width
#define cell_height self.contentView.height

@interface ConfirmOrderProductCell ()

@property (nonatomic, strong) UIImageView *iconView; // 商品图标
@property (nonatomic, strong) UILabel *nameLabel; // 商品名称
@property (nonatomic, strong) UILabel *skuLabel; // 商品规格
@property (nonatomic, strong) UILabel *priceLabel; // 商品价格
@property (nonatomic, strong) UILabel *amountLabel; // 数量

@end

@implementation ConfirmOrderProductCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.contentView.width = SCREEN_WIDTH;
        self.contentView.height = 80;
        [self _initViews];
    }
    
    return self;
}


#pragma mark -- 创建视图 --
- (void)_initViews {
    
    CGFloat x, y, width, height;
    
    // 商品图片
    x = 10;
    y = 10;
    width = cell_height - 2 * y;
    height = width;
    _iconView = [[UIImageView alloc] initWithFrame:CGRectMake(x, y, width, height)];
    _iconView.image = [UIImage imageWithColor:BLUE_COLOR];
    [self.contentView addSubview:_iconView];
    _iconView.center = CGPointMake(_iconView.center.x, cell_height / 2);
    
    // 商品名称
    x = _iconView.right + 5;
    y = _iconView.top;
    width = cell_width - x - 5;
    height = 20;
    _nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(x, y, width, height)];
    _nameLabel.font = FONT(12);
    _nameLabel.text = @"森森三合一潜水泵鱼缸过滤器鱼缸水泵增氧过滤水泵水族箱鱼缸潜水泵";
    _nameLabel.textColor = [UIColor darkGrayColor];
    _nameLabel.textAlignment = NSTextAlignmentLeft;
    [self.contentView addSubview:_nameLabel];
    
    
    // 商品规格
    x = _nameLabel.left;
    y = _nameLabel.bottom;
    _skuLabel = [[UILabel alloc] initWithFrame:CGRectMake(x, y, width, height)];
    _skuLabel.font = FONT(12);
    _skuLabel.text = @"颜色分类:黑色;规格:大";
    _skuLabel.textColor = [UIColor darkGrayColor];
    _skuLabel.textAlignment = NSTextAlignmentLeft;
    [self.contentView addSubview:_skuLabel];
    
    // 商品数量
    width = 80;
    x = cell_width - 20 - width;
    y = _skuLabel.bottom;
    _amountLabel = [[UILabel alloc] initWithFrame:CGRectMake(x, y, width, height)];
    _amountLabel.font = FONT(12);
    _amountLabel.text = @"x 2";
    _amountLabel.textColor = [UIColor darkGrayColor];
    _amountLabel.textAlignment = NSTextAlignmentRight;
    [self.contentView addSubview:_amountLabel];
    
    // 价格
    y = _skuLabel.bottom;
    x = _skuLabel.left;
    width = _amountLabel.left - 10 - x;
    _priceLabel = [[UILabel alloc] initWithFrame:CGRectMake(x, y, width, height)];
    _priceLabel.font = FONT(15);
    _priceLabel.text = @"￥2819";
    _priceLabel.textColor = SS_NAVI_ORANGE_COLOR;
    _priceLabel.textAlignment = NSTextAlignmentLeft;
    [self.contentView addSubview:_priceLabel];
    
}


#pragma mark - 重写set
- (void)setModel:(CartProductModel *)model {
    _model = model;
    
    [self _layoutViews];
}
// 重新布局视图
- (void)_layoutViews {
    
    // 商品图标
    [_iconView setImageURLStr:_model.icon_url placeholder:DEFAULT_IMAGE];
    // 名称
    _nameLabel.text = [NSString stringWithFormat:@"%@", _model.name];
    // 规格
    _skuLabel.text = [NSString stringWithFormat:@"%@", _model.sku_desc];
    // 价格
    _priceLabel.text = [NSString stringWithFormat:@"￥%@", _model.price];
    // 数量
    _amountLabel.text = [NSString stringWithFormat:@"x %@", _model.count];

}

@end
